/*
 * Copyright (C) 2009 Dimitrios C. Michalakos
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.cs.util.db.ioc;

/**
 * Thrown when the input or output data are invalid.
 * @author dimitris@jmike.gr
 */
public class IOCException extends Exception {

    private final String table;
    private final String column;
    private final IOCExceptionState state;

    /**
     * Constructs a new io controller exception with the designated state and null as its detail message.
     * @param table the table of the io controller that produced this exception.
     * @param column the column of the io controller that produced this exception.
     * @param state the state of the exception.
     */
    public IOCException(String table, String column, IOCExceptionState state) {
        super();
        this.table = table;
        this.column = column;
        this.state = state;
    }

    /**
     * Constructs a new io controller exception with the designated state and the specified detail message.
     * @param message a custom detail message.
     * @param table the table of the io controller that produced this exception.
     * @param column the column of the io controller that produced this exception.
     * @param state the state of the exception.
     */
    public IOCException(String message, String table, String column, IOCExceptionState state) {
        super(message);
        this.table = table;
        this.column = column;
        this.state = state;
    }
    
    /**
     * Returns the table of the io controller that produced this exception.
     * @return
     */
    public String getTable() {
        return table;
    }

    /**
     * Returns the column of the io controller that produced this exception.
     * @return
     */
    public String getColumn() {
        return column;
    }

    /**
     * Returns the error code of this exception.
     * @return
     */
    public int getErrorCode() {
        return state.code();
    }

    /**
     * Returns the state of this exception.
     * @return
     */
    public IOCExceptionState getStateEnum() {
        return state;
    }
}
